package com.xja.cloud.service;

import com.xja.cloud.entity.Order;
import com.xja.cloud.entity.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;


import java.util.ArrayList;
import java.util.List;

@Service("orderService")
public class OrderServiceImpl implements OrderService {

    private List<Order> orderList = new ArrayList<>();
    @Autowired
    private RestTemplate restTemplate;

    public OrderServiceImpl() {
        Order order1 = new Order(2,"周五晚餐","河北",2);
        Order order2 = new Order(1,"周日零食","北京",1);
        orderList.add(order1);
        orderList.add(order2);

    }

    @Override
    public List<Order> findOrderList() {

        for(Order order : orderList){
            String prodUrl = "http://APP-PROD/product/findDetail/{id}";
            Product product = restTemplate.getForObject(prodUrl, Product.class, order.getPid());
            System.out.println("订单系统调用商品服务,product:" + product);

        }
        return orderList;

    }
}
